{
 "cells": [
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Basic Libraries in Python \n",
    "\n",
    "## 1. Numpy\n",
    "### 1. Create Multiple Dimension Array"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "\n",
    "a = np.array([0, 1, 2, 3, 4, 5])\n",
    "print(a)\n",
    "\n",
    "b = np.array([[0, 1, 2], [3, 4, 5]])\n",
    "print(b)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "\n",
    "d = np.zeros(8)\n",
    "print(d)\n",
    "\n",
    "e = np.ones(8)\n",
    "print(e)\n",
    "\n",
    "# from 0-7\n",
    "f = np.arange(8)\n",
    "print(f)\n"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2. Shapes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "\n",
    "a = np.array([[0, 1, 2], [3, 4, 5]])\n",
    "\n",
    "print(np.shape(a))\n",
    "print(len(a)) # rows"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3. Operations"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "\n",
    "a = np.array([[0, 1, 2], [3, 4, 5]])\n",
    "\n",
    "\"matrix add operation\"\n",
    "print(a)\n",
    "print()\n",
    "print(a+3)  # add every elemetns by 3\n",
    "print()\n",
    "print(a*3)  # multiply every elemetns by 3\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "\n",
    "\"opertions between np array\"\n",
    "a = np.array([[0, 1, 2], [3, 4, 5]])\n",
    "b = np.array([[2, 0, 1], [5, 3, 4]])\n",
    "\n",
    "print(a)\n",
    "print()\n",
    "print(b)\n",
    "print()\n",
    "print(a+b)   \n",
    "print()\n",
    "print(a*b)  # multiple every element one by one by position\n",
    "\n",
    "\n"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 4. Access Numpy Array"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "\n",
    "a = np.array([[1,2,3],[4,5,6]])\n",
    "print(a[1][0])\n",
    "print(a[1][1])\n",
    "\n",
    "# access one row\n",
    "print(a[1])\n",
    "print(a[1,:])\n",
    "print()\n",
    "\n",
    "print(a)\n",
    "# modifiy the 2nd `col`\n",
    "a[:,1]=np.array([6,7])\n",
    "print(a)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2. matplotlib\n",
    "\n",
    "For draw chart, dispaly image and create a simple animations."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "# split form -5 to 5 as n units\n",
    "x = np.linspace(-5,5,60)\n",
    "print(np.shape(x))\n",
    "print(x.size)\n",
    "\n",
    "# Draw a line\n",
    "y = 2*x\n",
    "\n",
    "plt.plot(x,y)\n",
    "plt.show()"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Simple Charts"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "\n",
    "# Scatter Digram\n",
    "x =np.array([1.2,2.4,4.5,6.3, 0.7])\n",
    "y =np.array([2.2,3.4,3.5,2.3, 1.7])\n",
    "\n",
    "\n",
    "plt.scatter(x,y)\n",
    "plt.grid()\n",
    "plt.show()\n",
    "\n",
    "\n"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Issues\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "x = np.linspace(-3, 3, 50)\n",
    "\n",
    "y_1 = np.pi * x\n",
    "y_2 = x ** 2\n",
    "\n",
    "# Axis Label\n",
    "plt.xlabel(\"x val\", size=14)\n",
    "plt.ylabel(\"y val\", size=14)\n",
    "\n",
    "# Title\n",
    "plt.title(\"wow graph\")\n",
    "\n",
    "# Grid Box\n",
    "plt.grid()\n",
    "\n",
    "# Data\n",
    "plt.plot(x, y_1, label='y1')\n",
    "plt.plot(x, y_2, label='y2', linestyle='dashed')\n",
    "\n",
    "# Display lengend (图例)\n",
    "plt.legend()\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "\n",
    "def fn(x):\n",
    "    return  2 * x**3 + 3 * x**2 + 5*x + 4\n",
    "    \n",
    "x = np.linspace(-10, 10)\n",
    "y = fn(x)\n",
    "\n",
    "\n",
    "plt.xlabel(\"x\",size=14)\n",
    "plt.ylabel(\"y\",size=14)\n",
    "\n",
    "plt.plot(x,y)\n",
    "\n",
    "plt.grid()\n",
    "plt.legend()\n",
    "plt.show()\n",
    "\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.15"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
